//
//  AppDelegate.m
//  Finance
//
//  Created by mac on 2017/5/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#define UM_APPKEY @"593f53db7666131eba001bcf"
#define WX_APPKEY @"wxfed981e2b05e1fab"

#import "AppDelegate.h"
#import "ZZCTabBarController.h"
#import "ZZCHomeController.h"
#import "ZZCLoginController.h"
#import "WXApi.h"
#import "ZZCRequest.h"
//支付
#import <AlipaySDK/AlipaySDK.h>
#import "WXApiManager.h"


@interface AppDelegate ()<WXApiDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//    /* 打开调试日志 */
//    [[UMSocialManager defaultManager] openLog:YES];
//    
//    /* 设置友盟appkey */
//    [[UMSocialManager defaultManager] setUmSocialAppkey:UM_APPKEY];
//    //向微信注册wxd930ea5d5a258f4f
    [WXApi registerApp:WX_APPKEY];
    //[self configUSharePlatforms];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"USERLOAD"] == 1) {
        NSLog(@"已经登陆过");

    }
    self.window.rootViewController = [ZZCTabBarController new];
    
    [self.window makeKeyAndVisible];
    return NO;
}

- (void)configUSharePlatforms
{
    /* 设置微信的appKey和appSecret */
//    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_APPKEY appSecret:@"bb2780d0088f8bd5272e0b7649804250" redirectURL:@"http://mobile.umeng.com/social"];
}

// 支持所有iOS系统
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
//    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
//    if (!result) {
        // 其他如支付等SDK的回调
    NSLog(@"%d",[WXApi handleOpenURL:url delegate:self]);
         return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
//    }
//    return result;
   
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
//    if (!result) {
        // 其他如支付等SDK的回调
    NSLog(@"%d",[WXApi handleOpenURL:url delegate:self]);
        return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
//    }
//    return result;
    
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
    if ([url.host isEqualToString:@"safepay"]) {
        //跳转支付宝钱包进行支付，处理支付结果
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            NSLog(@"result = %@",resultDic);
        }];
         return YES;
    }else{
        NSLog(@"%d",[WXApi handleOpenURL:url delegate:self]);
        return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
    }
   
}




- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
